package com.gtq.uhome.service.serviceImpl;

import com.gtq.uhome.mapper.CategoryMapper;
import com.gtq.uhome.service.CategoryService;
import com.gtq.uhome.vo.CategoryVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;


/**
 * 商品品类管理
 */
@Service("categoryService")
public class CategoryServiceImpl implements CategoryService {

    @Resource
    CategoryMapper categoryMapper = null;


    //查询所有
    @Override
    public List<CategoryVo> findAll() {

        return categoryMapper.findAll();
    }

    //根据名称模糊查询
    @Override
    public List<CategoryVo> findLike(CategoryVo categoryVo) {

        return categoryMapper.findLike(categoryVo);
    }

    //商品品类管理，添加商品
    @Override
    public Boolean insertCategory(CategoryVo categoryVo) {

       /* List<CategoryVo> oneTwo = categoryMapper.findOneTwo();
        Integer twoId = categoryVo.getTwoId();
        for(int i = 0;i<oneTwo.size();i++){
            oneTwo.get(i).setTwoId(twoId);
        }*/

        categoryVo.setLevel("3");
        categoryVo.setStatusCode("0");

        List<CategoryVo> twoIds = categoryMapper.findTwoId(categoryVo.getTwoName());
        for (CategoryVo twoId : twoIds) {
            categoryVo.setTwoId(twoId.getTwoId());
            System.out.println("------------------"+twoId);
        }


        Integer lines = categoryMapper.insertCategory(categoryVo);

        return lines == 1;

    }

    //商品品类管理，修改商品数量
    @Override
    public Boolean updateCategory(CategoryVo categoryVo) {
        Integer lines = categoryMapper.updateCategory(categoryVo);
        return lines == 1;
    }

    //删除商品
    @Override
    public Boolean deleteCategory(List<CategoryVo> threeId) {
        Integer lines = -1;
        for (CategoryVo tid : threeId) {
            lines = categoryMapper.deleteCategory(tid.getThreeId());
        }
        //Integer lines = categoryMapper.deleteCategory(threeIds);
        return lines == 1;
    }
}